#include<bits/stdc++.h>
using namespace std;
namespace IO
{
	char buff[1<<21],*p1=buff,*p2=buff;
	char getch(){return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;}
	template<typename T>void read(T &x){char CH=getch();int fl=1;x=0;while(CH>'9'||CH<'0'){if(CH=='-')fl=-1;CH=getch();}while(CH<='9'&&CH>='0'){x=x*10+CH-48;CH=getch();}x*=fl;}
	template<typename T>void read_s(T &x){x="";char CH=getch();while(!(CH>='a'&&CH<='z')&&!(CH>='A'&&CH<='Z'))CH=getch();while((CH>='a'&&CH<='z')||(CH>='A'&&CH<='Z')){x+=CH;CH=getch();}}
	template<typename T,typename ...Args>void read(T &x,Args& ...args){read(x);read(args...);}
	char obuf[1<<21],*p3=obuf;
	void putch(char CH) {if(p3-obuf<(1<<21))*p3++=CH;else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=CH;}
	char CH[100];
	template<typename T>void write(T x) {if(!x)return putch('0');if(x<0)putch('-'),x*=-1;int top=0;while(x)CH[++top]=x%10+48,x/=10;while(top)putch(CH[top]),top--;}
	template<typename T,typename ...Args>void write(T x,Args ...args) {write(x);putch(' ');write(args...);}
	void put(string s){for(int i=0;i<s.size();i++)putch(s[i]);}
	void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
int n;
int a[200005],b[200005];
int cnt[400005],vis[400005],vis1[400005],vis2[400005];
vector<int>v[400005];
#define pii pair<int,int>
#define fi first
#define se second
priority_queue<pii>q;
int main()
{
	freopen("pairint.in","r",stdin);
	freopen("pairint.out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++) 
	{
		read(a[i],b[i]),++cnt[a[i]],v[a[i]].push_back(i);
		if(a[i]!=b[i]) ++cnt[b[i]],v[b[i]].push_back(i);
	}
	for(int i=1;i<=2*n;i++) q.push({-cnt[i],i});
	int ans=0;
	while(q.size())
	{
		int p=q.top().se,tmp=-q.top().fi;q.pop();
		if(cnt[p]!=tmp||vis2[p]||!cnt[p]) continue;
		vis2[p]=1;++ans;
		while(vis1[v[p].back()]) v[p].pop_back();
		int id=v[p].back();
		vis1[id]=1;
		--cnt[a[id]],vis[a[id]]=1;
		if(a[id]!=b[id]) --cnt[b[id]],vis[b[id]]=1;
		q.push({-cnt[a[id]],a[id]});q.push({-cnt[b[id]],b[id]});
	}
	write(ans);
	flush();
	return 0;
}
/*
20
16 15
19 8
7 17
14 19
1 8
19 19
6 8
14 6
17 7
*/
